package md.NJavaOppo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import md.NJavaBase.ICallbackQWEvent;
import md.NJavaBase.NJavaBase;
import md.NJavaBase.QWEvent;

public class OppoOnRequestPermissionsResult implements ICallbackQWEvent {
    //EVT_REQUEST_PERMISSIONS_RESULT 回调
    @Override
    public void reCall(QWEvent evt)
    {
        NJavaBase.logOut("Oppo","onActivityResult#4");
        Activity activity = NJavaBase.getActivity();
        int requestCode = (int)evt.Details;

        switch (requestCode) {
            /**
             *处理SDK申请权限的结果。
             */
            case OppoAd.REQUEST_PERMISSIONS_CODE:
                if (OppoAd.hasNecessaryPMSGranted()) {
                    /**
                     * 应用已经获得SDK运行必须的READ_PHONE_STATE、WRITE_EXTERNAL_STORAGE两个权限，直接请求广告。
                     */
                    //fetchSplashAd();
                    NJavaBase.logOut("OppoAd","用户同意授权");
                    OppoAd.initSDK();
                } else {
                    NJavaBase.logOut("OppoAd","用户拒绝授权");
                    /**
                     * 如果用户没有授权，那么应该说明意图，引导用户去设置里面授权。
                     */
                    Toast.makeText(activity, "应用缺少必须的READ_PHONE_STATE、WRITE_EXTERNAL_STORAGE两个权限！请点击\"应用权限\"，打开所需要的权限。", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.setData(Uri.parse("package:" + activity.getPackageName()));
                    activity.startActivity(intent);
                    activity.finish();
                }
                break;
            default:
                break;
        }
    }
}
